package cn.txun.springboot51.controller;

import cn.txun.springboot51.EmpMapper;
import cn.txun.springboot51.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    @Autowired
    private EmpMapper empMapper;
    @RequestMapping("/add")
    public int add(Emp emp){
        int rows = empMapper.insert(emp);
        return rows;
    }
    @RequestMapping("/select")
    //因为我们在类上添加@RestController，该注解会在每个方法上添加@ResponseBody
    //凡是添加@ResponseBody，springMVC框架将方法返回值转为JSON字符串
    //[{"id":"1","name":"关羽","job":"战士",“sal”:"3000"},
    // {"id":"2","name":"刘备","job":"战士",“sal”:"4000"}]
    public List<Emp> select(){
        return empMapper.select();
    }

    @RequestMapping("/delete")
    public int delete(int id){
        int row = empMapper.deleteById(id);
        return row;
    }
    @RequestMapping("/selectById")
    public Emp selectById(int id){
        return empMapper.selectById(id);
    }
    @RequestMapping("/update")
    public int update(Emp emp){
        return empMapper.update(emp);
    }
}
